home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / go32 / tables.asm < prev    next >
Encoding:
Assembly Source File  |  1994-07-30  |  4.1 KB  |  227 lines

  1. ; This is file TABLES.ASM
  2. ;
  3. ; Copyright (C) 1993 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14.  
  15. ;    History:20,1
  16.     title    tables
  17.     .386p
  18.  
  19.     include segdefs.inc
  20.     include tss.inc
  21.     include gdt.inc
  22.     include idt.inc
  23.  
  24. ;------------------------------------------------------------------------
  25.  
  26.     start_data16
  27.  
  28.     extrn    _tss_ptr:word
  29.     extrn    _was_exception:word
  30.     extrn    _npx:byte
  31.  
  32.     public  _was_user_int
  33. _was_user_int    dw    0
  34.  
  35.     public  ivec_number
  36. ivec_number    dw    ?
  37.  
  38. ; Don't include exception 17, as that's the BIOS equipment call :-(
  39. has_error    db    0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0
  40.  
  41.     public  _vector_78h
  42. _vector_78h    db    ?
  43.     public  _vector_79h
  44. _vector_79h    db    ?
  45.  
  46.     end_data16
  47.  
  48. ;------------------------------------------------------------------------
  49.  
  50.     .286c
  51.     start_bss
  52.  
  53.     public  _i_tss
  54. _i_tss  label    tss_s
  55.     db    type tss_s dup (?)
  56.  
  57.     public  _v74_tss
  58. _v74_tss    label    tss_s
  59.     db    type tss_s dup (?)
  60.  
  61.     public  _v78_tss
  62. _v78_tss    label    tss_s
  63.     db    type tss_s dup (?)
  64.  
  65.     public  _v79_tss
  66. _v79_tss    label    tss_s
  67.     db    type tss_s dup (?)
  68.  
  69.     end_bss
  70.     .386p
  71.  
  72. ;------------------------------------------------------------------------
  73.  
  74.     start_altcode16
  75.  
  76. sound    macro
  77.     local    foo
  78.     mov    al,033h
  79.     out    061h,al
  80.     mov    cx,0ffffh
  81. foo:
  82.     loop    foo
  83.     endm
  84.  
  85. ;ivec    macro    n
  86. ;    push    ds
  87. ;    push    g_rdata
  88. ;    pop    ds
  89. ;    mov    ivec_number,n
  90. ;    pop    ds
  91. ;    db    0eah
  92. ;    dw    0, g_itss
  93. ;    endm
  94. ;
  95. ;    public  _ivec0, _ivec1
  96. ;_ivec0:
  97. ;    ivec 0
  98. ;_ivec1:
  99. ;    x=1
  100. ;    rept 255
  101. ;     ivec x
  102. ;     x=x+1
  103. ;    endm
  104.  
  105.     public  _ivec0, _ivec1
  106. _ivec0:
  107.     push    ds        ;  1 byte
  108.     call    ivec_common    ;  3 bytes
  109. _ivec1:
  110. rept 255
  111.     push    ds        ;  1 byte
  112.     call    ivec_common    ;  3 bytes
  113. endm
  114.  
  115. ivec_common:
  116.     push    g_rdata
  117.     pop    ds
  118.     pop    ivec_number
  119.     sub    ivec_number, offset _ivec1;  pushes address *after* call
  120.     shr    ivec_number, 2
  121.     pop    ds
  122.     jmpt    g_itss
  123.  
  124.     end_altcode16
  125.     start_code16
  126.  
  127.     public  _interrupt_common
  128. _interrupt_common:
  129.     cli
  130.     mov    bx,g_rdata
  131.     mov    ds,bx
  132.     mov    bx,_tss_ptr
  133.     mov    ax,ivec_number
  134.     mov    [bx].tss_irqn,al
  135.     mov    esi,[bx].tss_esp
  136.     mov    fs,[bx].tss_ss        ; fs:esi -> stack
  137.     cmp    al,16            ; don't include bios equip call
  138.     ja    has_no_error
  139.     mov    di,ax
  140.     cmp    has_error[di],0
  141.     je    has_no_error
  142.     mov    eax,fs:[esi]
  143.     mov    [bx].tss_error,eax
  144.     add    esi,4
  145. has_no_error:
  146.     mov    eax,fs:[esi]        ; eip
  147.     mov    [bx].tss_eip,eax
  148.     mov    eax,fs:[esi+4]
  149.     mov    [bx].tss_cs,ax
  150.     mov    eax,fs:[esi+8]
  151.     mov    [bx].tss_eflags,eax
  152.     add    esi,12
  153.     mov    [bx].tss_esp,esi    ; store corrected stack pointer
  154.     mov    _was_exception,1
  155.     jmpt    g_ctss            ; pass control back to real mode
  156.     cli
  157.     jmp    _interrupt_common    ; it's a task
  158.  
  159.     extrn    graphics_fault:near
  160.  
  161.     public  _page_fault
  162. _page_fault:
  163.     cli
  164.     mov    bx,g_rdata
  165.     mov    ds,bx
  166.     mov    es,bx
  167.     mov    eax,cr2
  168. if 1
  169. ;;
  170. ;; CB changes: added 16MB paging areas
  171. ;; OLD:
  172. ;;    cmp    eax,0e0000000h
  173. ;;    jb    regular_pf
  174. ;;    cmp    eax,0e0300000h
  175. ;;    ja    regular_pf
  176. ;;
  177.     cmp    eax,0e0000000h
  178.     jb    regular_pf
  179.     cmp    eax,0e0300000h
  180.     jb    graphics_pf
  181.     cmp    eax,0e1000000h
  182.     jb    regular_pf
  183.     cmp    eax,0e4000000h
  184.     jae    regular_pf
  185. graphics_pf:
  186. ;;
  187. ;; end CB changes
  188. ;;
  189.     jmp    graphics_fault
  190. regular_pf:
  191. endif
  192.     mov    bx,_tss_ptr
  193.     mov    [bx].tss_irqn,14    ; page fault
  194.     mov    [bx].tss_cr2,eax
  195.     pop    eax
  196.     mov    [bx].tss_error,eax
  197.     mov    eax,0
  198.     mov    cr2,eax            ; so we can tell INT 0D from page fault
  199.     mov    _was_exception,1
  200.     jmpt    g_ctss
  201.     jmp    _page_fault
  202.  
  203. v_handler    macro    label,vector
  204.     public  label
  205. label:
  206.     cli
  207.     mov    bx,g_rdata
  208.     mov    ds,bx
  209.     mov    es,bx
  210.     mov    bx,_tss_ptr
  211.     mov    al,vector
  212.     mov    [bx].tss_irqn,al
  213.     mov    _was_exception,1
  214.     jmpt    g_ctss
  215.     jmp    label
  216.     endm
  217.  
  218.     v_handler    _v74_handler, 74h
  219.     v_handler    _v78_handler, _vector_78h
  220.     v_handler    _v79_handler, _vector_79h
  221.  
  222.     end_code16
  223.  
  224. ;------------------------------------------------------------------------
  225.  
  226.     end
  227.